#!/usr/bin/env python3
# encoding: utf-8
# coding style: pep8
# ====================================================
#   Copyright (C) 2021  All rights reserved.
#
#   Author        : Jinjing Li
#   Email         : josiahleeoaa@outlook.com
#   File Name     : plot_spfission.py
#   Last Modified : 2021-08-18 17:06
#   Describe      :
#
# ====================================================

#-*- coding:utf8 -*-
#Powered by Jinjing Li @2021-08-17 19:53:26


import os,sys
from ROOT import TFile,TH1D,TCanvas,TLegend

sys.path.append("/Users/josiahlee/WORK/jinpingStyle/");
print(sys.path)

from pyroot_opt_module import opt_hist_style

if __name__=='__main__':

    output_file=TFile(sys.argv[1],"READ")

    c1=TCanvas()
    lg0=TLegend(0.5,0.5,0.8,0.9)
    h_nnu=output_file.Get("h_nnu")
    h_pnu=output_file.Get("h_pnu")
    opt_hist_style(h_nnu, xrange=[0,20], xtitle='Number of particles', ytitle='Entries')
    opt_hist_style(h_pnu, xrange=[0,20], lcolor=2)
    lg0.AddEntry(h_nnu,"neutron","l")
    lg0.AddEntry(h_pnu,"gamma","l")
    h_nnu.Draw()
    h_pnu.Draw("same")
    lg0.Draw()
    c1.Show()
    c1.SaveAs("Plots/spfission_U235_numbers.pdf")

    c2=TCanvas()
    lg=TLegend(0.5,0.5,0.8,0.9)
    for i in range(5):
        #h_neng=output_file.Get("h_neng_%d"%(i+1))
        h_neng=output_file.Get("h_peng_%d"%(i+1))
        if i==0:
            #opt_hist_style(h_neng, xrange=[0,10], xtitle='Energy [MeV]', yrange=[1,h_neng.GetMaximum()*1.5], ytitle='Entries', xdivisions=508)
            opt_hist_style(h_neng, xrange=[0,10], xtitle='Energy [MeV]', yrange=[1,h_neng.GetMaximum()*3.0], ytitle='Entries', xdivisions=508)
            h_neng.Draw()
        else:
            opt_hist_style(h_neng, lcolor=i+1,lstyle=1)
            h_neng.Draw('same')

        lg.AddEntry(h_neng,"N=%d"%(i+1),"l")
    lg.Draw()
    c2.Show()
    #c2.SaveAs("Plots/spfission_U235_energy_neutron.pdf")
    c2.SaveAs("Plots/spfission_U235_energy_gamma.pdf")
